//
//  ZDServiceController.m
//  ZDPension
//
//  Created by 刘甲奇 on 2017/6/14.
//  Copyright © 2017年 maker. All rights reserved.
//

#import "ZDServiceController.h"
#import "ZDLeftCategoryController.h"
#import "ZDRightServiceController.h"
#import "ZDSelectListController.h"
#import "ZDStoreDetialController.h"

@interface ZDServiceController ()
/**
 <#Description#>
 */
@property(nonatomic,strong)ZDSelectListController *selectController;
/**
 <#Description#>
 */
@property(nonatomic,strong)UIButton *rightButton;
@end

@implementation ZDServiceController

- (void)setupUI
{
    self.title = self.model.gc_name;
    
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setTitle:@"离我距离(全部)" forState:0];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
    rightButton.frame = CGRectMake(0, 0, 120, 30);
    [rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
    self.rightButton = rightButton;
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    [self setupChirldController];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectDistance:) name:SELECT_DISTANCE_NOTIFICATION object:nil];
}
- (void)setupChirldController
{
    ZDLeftCategoryController *left = [[ZDLeftCategoryController alloc] init];
    left.model = self.model;
    left.view.frame = CGRectMake(0, 0, 100, self.view.height);
    [self.view addSubview:left.view];
    [self addChildViewController:left];
    
    ZDRightServiceController *right = [[ZDRightServiceController alloc] init];
    right.view.frame = CGRectMake(100, 0, LEScreenWidth -100, self.view.height);
    [self.view addSubview:right.view];
    [self addChildViewController:right];
    left.delegate = right;
    
    ZDSelectListController *select = [[ZDSelectListController alloc] init];
    select.view.frame = self.view.bounds;
    self.selectController = select;
    [self addChildViewController:select];
    
}

#pragma mark- 点击事件
- (void)rightClick
{
    ZDLog(@"%s---%d---点击了右侧",__func__,__LINE__);
    [self.view addSubview:self.selectController.view];
}
- (void)selectDistance:(NSNotification *)notification
{
    [self.selectController.view removeFromSuperview];
    NSIndexPath *indexPath = notification.object;
    NSString *title = @"";
    if (indexPath.row == 0) {
        title = @"离我距离(1KM)";
    }else if (indexPath.row == 1){
        title = @"离我距离(3KM)";
    }else if (indexPath.row == 2){
        title = @"离我距离(5KM)";
    }else if (indexPath.row == 3){
        title = @"离我距离(8KM)";
    }else if (indexPath.row == 4){
        title = @"离我距离(全部)";
    }else if (indexPath.row == 10){
        ZDLog(@"%s---%d---点击了空白",__func__,__LINE__);
        return;
    }
    [self.rightButton setTitle:title forState:0];
}

@end








